//
//  HomeViewController.swift
//  firstSwiftWeiBo
//
//  Created by Inverno on 16/12/5.
//  Copyright © 2016年 Inverno. All rights reserved.
//

import UIKit

class HomeViewController: BaseViewController {

    lazy var titleButton : TitleButton = TitleButton()
    lazy var popoverAnimator : PopoverAnimator = PopoverAnimator { [weak self] (presented) -> (Void) in
        self?.titleButton.selected = presented
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        visitView.setup(imageName: "visitordiscover_feed_image_house")
        visitView.needRotate = true
        
        setupNavBar()
    }

}


extension HomeViewController {
    private func setupNavBar() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_friendattention")
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: "navigationbar_pop")
        
        titleButton.setTitle("yanhan", forState: .Normal)
        titleButton.addTarget(self, action: "titleBtnClick", forControlEvents: .TouchUpInside)
        navigationItem.titleView = titleButton
        
    }
}

extension HomeViewController {
    @objc private func titleBtnClick() {
        // 1.创建弹出控制器
        let popoverVc = PopoverViewController()
        
        // 2.设置弹出样式
        popoverVc.modalPresentationStyle = .Custom
        
        // 3.设置转场代理
        popoverVc.transitioningDelegate = popoverAnimator
        
        // 4.弹出
        presentViewController(popoverVc, animated: true, completion: nil)
    }
}